/*
 * @Author: YNT 2501512800@qq.com
 * @Date: 2022-07-25 00:06:36
 * @LastEditors: YNT 2501512800@qq.com
 * @LastEditTime: 2022-09-07 08:39:23
 * @FilePath: \洋安未来社区\pages\toolbar\passList\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { comm } from '../../../behaviors/index'
import Toast from '@vant/weapp/toast/toast'
import SpecialModel from '../../../api/special'

Page({
  behaviors: [comm],
  data: {
    nvabarData: {
      navigationBarTextStyle: 'black', // 胶囊主题 white || black
      navigationBarBackground: '#ffffff', // 导航栏背景色
      navigationBarTitleText: '访客列表',
    },
    outTabsArr: [{ name: 'visit' }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  onMyEvent(event) {
    wx.showLoading({ title: '加载中...', mask: true })
    let { initPage, initPageSize, curTabIndex, activeTab } = event.detail
    SpecialModel.passList()
      .then(({ data: curData }) => {
        let pageCount = Math.ceil(curData.total / initPageSize)
        // 关闭首次加载loading
        activeTab.isLoaded = true
        // 若为首页则直接替换
        activeTab.dataLists =
          activeTab.page === initPage
            ? curData.items
            : dataLists.concat(curData.items)
        this.setData({
          [`outTabsArr[0]`]: activeTab,
        })
        // 根据实际数据设置 loadmore组件 当前状态
        activeTab.loadMoreView.loadMoreComplete({
          curPage: activeTab.page,
          pageCount,
        })
      })
      .catch((err) => {
        let pageCount = 0
        // 关闭首次加载loading
        activeTab.isLoaded = true
        // 若为首页则直接替换
        activeTab.dataLists = []
        this.setData({
          [`outTabsArr[0]`]: activeTab,
        })
        // 根据实际数据设置 loadmore组件 当前状态
        activeTab.loadMoreView.loadMoreComplete({
          curPage: activeTab.page,
          pageCount,
        })

        // 加载出错 且非第一页则展示 从新加载当前页按钮
        if (activeTab.page != initPage) {
          activeTab.loadMoreView.loadMoreFail()
        }
      })
      .finally(wx.hideLoading())
  },

  // 跳转详情
  skipDetail(event) {
    let id = event.detail
    wx.navigateTo({
      url: `/subPackages/topicPackages/pages/social/socialDetail/index?id=${id}`,
    })
  },
})
